﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Web;

namespace Test_API
{
    class InitAndPingTest
    {
        protected string rootUrl = "http://spring/ws13/13ws-37789/_vti_bin/L2PServices/api.svc/v1/";
        //protected string rootUrl = "https://www3.elearning.rwth-aachen.de/_vti_bin/L2PServices/api.svc/v1/";
        //protected string rootUrl = "https://demo2.elearning.rwth-aachen.de/_vti_bin/L2PServices/api.svc/v1/";
        protected string accesstoken { get; set; }
        protected virtual string moduleName { get { return "Ping"; } }
        private string pingMethod = "ping";

        private string p;

        private string queryStringGenerate()
        {
            string queryString = new Dictionary<string, string>() { { "p", this.p }, { "accesstoken", this.accesstoken } }.buildQueryString();

            return queryString;
        }

        public InitAndPingTest(string accessToken)
        {
            this.accesstoken = accessToken;
        }

        public List<LogEntry> start()
        {
            Console.WriteLine("Ping begin\n============");
            List<LogEntry> entries = new List<LogEntry>();

            LogEntry pingEntry = new LogEntry(this.moduleName, true);
            this.p = Guid.NewGuid().ToString()+" @"+DateTime.Now.ToString("U");
            HTTP.execute(HTTP.RequestType.GET, this.rootUrl, this.pingMethod, this.queryStringGenerate(), null, ref pingEntry);

            entries.Add(pingEntry);
            return entries;
        }
    }
}
